package com.chat.service;

import com.chat.Local;
import com.chat.common.ChatMsg;
import com.chat.common.Message;
import com.chat.common.MessageType;
import com.chat.view.MainWindowView;
import javafx.application.Platform;

import java.text.SimpleDateFormat;
import java.util.Date;

/*
    群聊
 */
public class GroupChat {
       public void GroupChatText(String userid,String nickname,String groupid,String content){//文字群聊
              Message msg=new Message();
              msg.setMesType(MessageType.MESSAGE_GROUP_CHAT_TEXT);
              ChatMsg cm=new ChatMsg();
              Date date = new Date();
              SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
              cm.setTime(dateFormat.format(date));
              cm.setContent(content);
              cm.setReceive(groupid);
              cm.setSenderid(userid);
              cm.setSendernickname(nickname);
              msg.setData(cm);
              ClientConnectServerThread clientConnectServerThread=ManageClientConnectServerThread.getClientConnectServerThread(Local.user.getUsername());
              clientConnectServerThread.send(msg);
              Platform.runLater(()-> {
                     ((javafx.scene.control.TextArea) MainWindowView.$("inputbox")).setText("");
              });
       }
       public void groupchatimage(String senderid,String sendernickname,String receive,String filename,byte[] file){//图片群聊
              Message msg=new Message();
              ChatMsg cm=new ChatMsg();
              msg.setMesType(MessageType.MESSAG_GROUP_CHAT_IMAGE);
              Date date = new Date();
              SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
              cm.setTime(dateFormat.format(date));
              cm.setSenderid(senderid);
              cm.setSendernickname(sendernickname);
              cm.setReceive(receive);
              cm.setFilename(filename);
              cm.setFile(file);
              msg.setData(cm);
              ClientConnectServerThread clientConnectServerThread=ManageClientConnectServerThread.getClientConnectServerThread(Local.user.getUsername());
              clientConnectServerThread.send(msg);
       }
        public void groupchatfile(String senderid,String sendernickname,String receive,String address,String filename,String time){
               Message msg=new Message();
               msg.setMesType(MessageType.MESSAGE_GROUP_CHAT_FILE);
               ChatMsg cm=new ChatMsg();
               cm.setTime(time);
               cm.setSenderid(senderid);
               cm.setSendernickname(sendernickname);
               cm.setReceive(receive);
               cm.setAddress(address);
               cm.setFilename(filename);
               cm.setType("3");
               msg.setData(cm);
               ClientConnectServerThread clientConnectServerThread=ManageClientConnectServerThread.getClientConnectServerThread(Local.user.getUsername());
               clientConnectServerThread.send(msg);

              }
}
